<?php
namespace Enkuso\PropertyBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Nimo\Bundle\BookstoreApiBundle\Entity\Book\Category;

class LoadBookCategoryData extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * {@inheritDoc}
     */
    public function load(ObjectManager $manager)
    {
        $data = array(
            'literature'    =>  'Уран зохиол',
            'sport'         =>  'Спорт',
            'health'        =>  'Эрүүл мэнд',
            'business'      =>  'Бизнэс',
            'education'     =>  'Сурах бичиг',
            'history'       =>  'Түүх',
            'foreign'       =>  'Гадаад уран зохиол',
            'poem'          =>  'Шүлэг',
            'tutorial'      =>  'Сургалт, гарын авлага',
            'story'         =>  'Үлгэр'
        );

        foreach ($data as $key => $c){
            $category = new Category();
            $category->setName($c);
            $manager->persist($category);
            $this->addReference('book-category-'.$key, $category);
        }

        $manager->flush();
    }

    /**
     * {@inheritDoc}
     */
    public function getOrder()
    {
        return 98; // the order in which fixtures will be loaded
    }
}
